package cn.ym.mall.service.impl;

import cn.ym.mall.dao.StoreDao;
import cn.ym.mall.dao.impl.StoreDaoImpl;
import cn.ym.mall.entity.Store;
import cn.ym.mall.service.StoreService;
import cn.ym.mall.utils.DruidUtils;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 赵金明
 * 2022/8/12
 */
public class StoreServiceImpl implements StoreService {
    StoreDao storeDao = new StoreDaoImpl();
    /**
     * 新增商店
     *
     * @param store
     * @return
     * @throws SQLException
     */
    @Override
    public boolean addStore(Store store) throws SQLException {
        return storeDao.addStore(store) == 1;
    }

    /**
     * 根据id删除商店
     *
     * @param sid
     * @return
     * @throws SQLException
     */
    @Override
    public boolean deleteBySid(Integer sid) throws SQLException {
        return storeDao.deleteBySid(sid) == 1;
    }

    @Override
    public Store getStoreBySid(Integer sid) throws SQLException {
        Connection conn = null;
        Store store = null;
        try {
            conn = DruidUtils.getConnection();
            store = storeDao.getStoreBySid(sid);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DruidUtils.close();
        }
        return store;
    }
}
